package pATT.profilingAlgorithm.PersonalSearcher;
/***************************************************************************
 *                                RAMObjectPager                           * 
 *                       initial version by: Travis Bauer                  *
 *                      copyright (C) 2002 IGLU Research Group             *
 *                              trbauer@indiana.edu                        *
 ***************************************************************************/
/***************************************************************************
 * The licence for this code is included in LICENSE.txt.  If you did not   *
 * get this file with this distribution, request a copy from               *
 * iglu@cs.indiana.edu                                                     *
 ***************************************************************************/
import java.util.HashMap;
import java.util.Iterator;

/**
 * A simple implementation of ObjectPager which does no paging.
 * It keeps all objects in RAM.  This is useful as a default ObjectPager
 * because it requires no special startup parameters.
 *
 * @see iglu.util.ObjectPager
 * 
 * @author <a href="trbauer@indiana.edu">Travis Bauer</a>
 */
public class RAMObjectPager implements ObjectPager {
  public HashMap map = new HashMap();
  int nextId = 0;

  /** Create a new RAMObjectPager */
  public RAMObjectPager() {
  }

  @SuppressWarnings("unchecked")
public synchronized Object store(Object o) {
    Integer i = new Integer(nextId);
    nextId++;
    map.put(i, o);
    return i;
  }
  
  public synchronized Object retrieve(Object id) {
    return map.get(id);
  }
  
  @SuppressWarnings("unchecked")
public synchronized void update(Object o, Object id) {
    map.put(id, o);
  }
  
  public synchronized void delete(Object id){
    map.remove(id);
  }
  
  public synchronized Iterator iterator() {
    return map.keySet().iterator();
  }
}
